package com.meiyou.controller;

import com.meiyou.dto.CollectDto;
import com.meiyou.result.Result;
import com.meiyou.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    /**
     * 点赞、取消点赞文章
     *
     * @param collectDto
     * @return
     */
    @PostMapping
    public Result collectOrCancel(@RequestBody CollectDto collectDto) {

        collectService.collectOrCancel(collectDto);

        return Result.success("操作成功！");
    }

    /**
     * 获取用户文章被收藏数
     *
     * @return
     */
    @GetMapping
    public Result<Integer> getCollectNum() {

        Integer count = collectService.getCollectNum();

        return Result.success(count);
    }

    /**
     * 批量删除收藏文章
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result removeBatch(@RequestParam List<Long> ids) {

        collectService.removeBatch(ids);

        return Result.success("删除成功！");
    }

}

